#include "Retirementplanner.h"

RetirementPlanner::RetirementPlanner(void)
{
     dContribution = 0;
     dInterestRate = 0;
     dInterestEarned = 0;
     iYearsOfSaving = 0;
     dFutureValue = 0;
     dPresentValue = 0;
     dInflation = 0;
     iCurAge = 0;
     iRetireAge = 0;
}

RetirementPlanner::~RetirementPlanner(void)
{
}

void RetirementPlanner::setCurAge(int iAgeNow)
{
     iCurAge = iAgeNow;
}

void RetirementPlanner::setRetireAge(int iAgeThen)
{
     iRetireAge = iAgeThen;
}

void RetirementPlanner::setContribution(double dContribute)
{
     dContribution = dContribute;
}

void RetirementPlanner::setInterestRate(double dInterest)
{
     dInterestRate = dInterest;
}

void RetirementPlanner::setInflation(double dInflate)
{
	dInflation = dInflate;
}

double RetirementPlanner::calcFutureValue(void)
{
     iYearsOfSaving = iRetireAge - iCurAge;
     dFutureValue = 0;
     for (int i=0; i < iYearsOfSaving; i++) {
          dFutureValue += 1;
          dFutureValue *= (1+(dInterestRate/100));
     }
     dFutureValue *= dContribution;
     dInterestEarned = dFutureValue - 
          (dContribution * iYearsOfSaving);
     return dFutureValue;
}

double RetirementPlanner::calcPresentValue(void) {
     double dFutureValue = calcFutureValue();
     for(int i = 0; i < iYearsOfSaving; i++) {
          dFutureValue /= (1 + (dInflation/100));
     }
     dPresentValue = dFutureValue;
     return dPresentValue;
}